package com.usian.admin.controller;

import com.usian.admin.service.AdChannelService;
import com.usian.apis.admin.AdChannelControllerApi;
import com.usian.model.admin.dtos.ChannelDto;
import com.usian.model.admin.pojos.AdChannel;
import com.usian.model.common.dtos.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/channel")
@Api(tags = "频道管理")
public class AdChannelController implements AdChannelControllerApi {

    @Autowired
    private AdChannelService channelService;

    //查询
    @Override
    @PostMapping("/list")
    @ApiOperation(value = "查询频道信息",notes = "根据名称分页查询频道列表")
    // 多个参数用以下注解
    //@ApiOperation(value = "查询商品列表",notes = "分页查询")
    //@ApiImplicitParams({
    //        @ApiImplicitParam(name = "page",type ="Integer",value = "页码"),
    //        @ApiImplicitParam(name = "rows",type ="Integer",value = "条数")
    //  }
    //)
    public ResponseResult findByNameAndPage(@RequestBody ChannelDto dto) {
        return channelService.findByNameAndPage(dto);
    }
    @ApiOperation(value = "查询频道信息",notes = "单纯查询频道列表")
    @GetMapping("/channels")
    @Override
    public ResponseResult findAll() {
        return channelService.findAll();
    }


    //增加
    @PostMapping("/save")
    @ApiOperation(value = "添加频道信息",notes = "添加频道列表")
    @Override
    public ResponseResult Add(@RequestBody AdChannel ad) {
        return channelService.Add(ad);
    }

    //删除
    @DeleteMapping("/del/{id}")
    @ApiOperation(value = "删除频道信息",notes = "删除频道列表")
    @Override
    public ResponseResult Del(@PathVariable Integer id) {
        return channelService.Del(id);
    }

    //修改
    @PostMapping("/update")
    @ApiOperation(value = "修改频道信息",notes = "修改频道列表")
    @Override
    public ResponseResult Upt(@RequestBody AdChannel ad) {
        return channelService.Upt(ad);
    }
}
